import time

from django.db import models


class UrlController(models.Model):
    """路由控制"""

    id = models.AutoField(primary_key=True)
    intro = models.CharField(max_length=256, default="")  # 简要介绍
    role = models.CharField(max_length=64)  # 路由规则
    permission_level = models.IntegerField()  # 需要访问的等级
    is_delete = models.IntegerField(default=0)  # 是否删除

    class Meta:
        db_table = "url_controller"


class BlackHouse(models.Model):
    """Go where you should f**k go"""

    id = models.AutoField(primary_key=True)
    host = models.CharField(max_length=64, default="")  # 请求来源
    last_time = models.IntegerField(default=time.time())  # 上次请求时间
    has_count = models.IntegerField(default=10)  # 剩余的请求次数 正常范围 30s内限制10次 如果超出 每多一次非法请求 level等级提升1
    free_time = models.IntegerField(default=0)  # 下次释放时间
    valid_level = models.IntegerField(default=0)  # 风险等级 1~10 10就会被封禁
    control_num = models.IntegerField(default=0)  # 总控次数
    invalid = models.IntegerField(default=0)  # 是否封禁

    class Meta:
        db_table = "black_house"
